package com.ruoyi.medical.clinic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medical.clinic.domain.Clinic;
import com.ruoyi.medical.clinic.service.IClinicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医务室信息Controller
 * 
 * @author wad
 * @date 2022-04-06
 */
@RestController
@RequestMapping("/medical/clinic")
public class ClinicController extends BaseController
{
    @Autowired
    private IClinicService clinicService;

    /**
     * 查询医务室信息列表
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:list')")
    @GetMapping("/list")
    public TableDataInfo list(Clinic clinic)
    {
        startPage();
        List<Clinic> list = clinicService.selectClinicList(clinic);
        return getDataTable(list);
    }

    /**
     * 导出医务室信息列表
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:export')")
    @Log(title = "医务室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Clinic clinic)
    {
        List<Clinic> list = clinicService.selectClinicList(clinic);
        ExcelUtil<Clinic> util = new ExcelUtil<Clinic>(Clinic.class);
        util.exportExcel(response, list, "医务室信息数据");
    }

    /**
     * 获取医务室信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:query')")
    @GetMapping(value = "/{clinicId}")
    public AjaxResult getInfo(@PathVariable("clinicId") Long clinicId)
    {
        return AjaxResult.success(clinicService.selectClinicByClinicId(clinicId));
    }

    /**
     * 新增医务室信息
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:add')")
    @Log(title = "医务室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Clinic clinic)
    {
        return toAjax(clinicService.insertClinic(clinic));
    }

    /**
     * 修改医务室信息
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:edit')")
    @Log(title = "医务室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Clinic clinic)
    {
        return toAjax(clinicService.updateClinic(clinic));
    }

    /**
     * 删除医务室信息
     */
    @PreAuthorize("@ss.hasPermi('medical:clinic:remove')")
    @Log(title = "医务室信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clinicIds}")
    public AjaxResult remove(@PathVariable Long[] clinicIds)
    {
        return toAjax(clinicService.deleteClinicByClinicIds(clinicIds));
    }
}
